package com.lanou.wuyou.gift.category;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.lanou.wuyou.gift.R;
import com.lanou.wuyou.gift.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 17/3/14.
 */

public class CategoryFragment extends BaseFragment{
    private ViewPager viewPager;
    private TabLayout tabLayout;
    private CategoryVPAdapter adapter;
    private String[] titles = {"攻略","单品"};
    private String[] urls = {
            "http://api.liwushuo.com/v2/channel_groups/all",
            "http://api.liwushuo.com/v2/item_categories/tree",
            "http://api.liwushuo.com/v2/columns"
    };
    public static CategoryFragment newInstance(){

        Bundle args = new Bundle();
        CategoryFragment fragment = new CategoryFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    public int setLayout() {
        return R.layout.fragment_category;
    }

    @Override
    public void initView(View view) {
        viewPager = (ViewPager) view.findViewById(R.id.view_pager_category);
        tabLayout = (TabLayout) view.findViewById(R.id.tab_layout_category);
        adapter = new CategoryVPAdapter(getChildFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

        List<Fragment> fragments = new ArrayList<>();
        fragments.add(CategoryStrategyFragment.newInstance(urls));
        fragments.add(CategoryProductFragment.newInstance(urls[1]));

        adapter.setFragments(fragments);
        for (int i = 0; i < titles.length; i++) {
            tabLayout.getTabAt(i).setText(titles[i]);
        }
    }

    @Override
    public void initData() {

    }
}
